import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-12-16
 * Time: 14:28
 */
class Person implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Exception1 {
    private static int num(int a){
        try {
            if (a == 0){
                throw new ArithmeticException("算数异常");
            }
            return a;
        } catch (ArithmeticException e) {
            e.printStackTrace();
        }finally {
            return 30;
        }
    }

    public static void main(String[] args) {
        System.out.println(num(10));
    }



    public static void main4(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int[] arry = null;
            System.out.println(arry.length);
            System.out.println("hello");
        } catch (ArithmeticException e) {
            System.out.println("捕获到了一个空指针异常或算数异常");
            e.printStackTrace();

        } finally {
            System.out.println("关闭资源");
        }
        System.out.println("我是其他代码逻辑");
    }



    public static void fun(int n) throws CloneNotSupportedException {
        if (n < 0){
            throw new CloneNotSupportedException("受查异常继续处理");
        }

    }
    public static void main3(String[] args) throws CloneNotSupportedException {

            fun(-1);

    }






    public static void main2(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2  = (Person) person1.clone();
    }




    public static void func(){
        func();
    }
    public static void main1(String[] args) {
        func();
    }
}
